<template>
  <div class="flex-container">
  <div class="parent_box">
    <div class="sub_box">
      <img class="sub_box_img" src="https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKYL5rCmOPfxXbHfUYib0ZBJtOxrWFABpOEWHKHiaWjP7NmMsiabZDIuznIibHYQNKicH5ic7a5h4jZ2ZjA/132" alt="">
      <span class="sub_box_name">{{userData.userName}}</span>
      <span class="sub_box_state">{{userData.email}}</span>
    </div>
    <div class="demo-type">
      <div class="demo-type-div">
        <span class="demo-type-div-num">769.8万</span>
        <span class="demo-type-div-state">获赞</span>
      </div>
      <div class="demo-type-div">
        <span class="demo-type-div-num">24</span>
        <span class="demo-type-div-state">关注</span>
      </div>
      <div class="demo-type-div">
        <span class="demo-type-div-num">84.1万</span>
        <span class="demo-type-div-state">粉丝</span>
      </div>
    </div>
    <div class="demo-collapse">
      <el-collapse >
        <el-collapse-item disabled="true" @click="router.push('/userArticles')" name="1">
          <template #title>
            <el-icon >
              <Operation />
            </el-icon><span class="title-span">
            &nbsp;我的文章</span>
          </template>
        </el-collapse-item>
        <el-collapse-item disabled="true"  name="2">
          <template #title>
            <el-icon >
              <Operation />
            </el-icon><span class="title-span">
            &nbsp;个人信息</span>
          </template>
        </el-collapse-item>
        <el-collapse-item disabled="true" @click.prevent="quit();" name="3">
          <template #title>
            <el-icon >
              <Operation />
            </el-icon>
            <span class="title-span">
              &nbsp;退出登录
            </span>

          </template>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
  <czr-footer-main />
  </div>
</template>

<script setup >
import {Operation} from '@element-plus/icons-vue'
import {useUserToken} from "@/store/counter";
import {onMounted,ref} from "vue";
import {getUserNameById} from "@/http/user";
import {useRouter} from "vue-router";
import { ElMessage, ElMessageBox } from 'element-plus'

const router=useRouter();
const userToken=useUserToken();
const userId=userToken.user.id;
let userData=ref({})
onMounted(()=>{
  loadData()
})
function loadData(){
  getUserNameById(userId).then(res=>{
    userData.value=res.data.userinfo;
  })
}
const quit = () => {

  ElMessageBox.confirm(
      '',
      '你确定要退出登录吗',
      {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning',
        center: true,
      }
  )
      .then(() => {
        userToken.setUserToken("");
        router.push("/login")
        ElMessage({
          type: 'success',
          message: '成功退出',
        })
      })
}
</script>

<style scoped>
.flex-container{
  display: flex;
  flex-direction: column;
  min-height: 100vh; /* 确保父级元素至少占满视口高度 */
}
.demo-type {
  padding: 1em 0 2em 0;
  width: 100%;
  display: flex;
}
.demo-type > div {
  flex: 1;
  text-align: center;
}

.demo-type > div:not(:last-child) {
  border-right: 1px solid var(--el-border-color);
}
.parent_box{
  flex-wrap: wrap;
  display: flex;
  justify-content: space-between;

}
.sub_box{
  flex-direction: column;
  background: #62A8EA;
  width: 100%;
  height: 18em;
  display: flex;
  justify-content: center;
  align-items: center;
}
.demo-type-div{
  display: flex;
  flex-direction: column;
}
.demo-collapse {
  width: 100%;
  padding: 0 1em;
}
.sub_box_img{
  width: 7em;
  border-radius: 65px;
  height: 7em;
}
.sub_box_name {
  font-size: 1.3em;
  color: aliceblue;
  padding-top: 1em;
}
.sub_box_state {
  padding-top: 4px;
  color: aliceblue;
  font-size: 12px;
}
.demo-type-div-num {
  color: #62A8EA;
}
.demo-type-div-state {
  font-size: 0.5em;
}
.title-span{
  color: #222222;
}
</style>